package jmind.core.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;


/**
 * selenium
 https://blog.csdn.net/qq_22003641/article/details/79137327
 * http://www.chinadrugtrials.org.cn/clinicaltrials.searchlist.dhtml
 * <p>
 * http://www.chinadrugtrials.org.cn/clinicaltrials.searchlistdetail.dhtml
 *
 *
 * selenium  自动化测试模拟浏览器
 * https://blog.csdn.net/qq_22003641/article/details/79137327
 *
 * firefox驱动
 * https://npm.taobao.org/mirrors/geckodriver/v0.29.0/
 * chrome驱动
 * https://npm.taobao.org/mirrors/chromedriver
 *
 * http://selenium-release.storage.googleapis.com/index.html
 * https://www.cnblogs.com/meiling-ji/p/5283476.html
 *   mac 启动 SafariDriver
 *   https://blog.csdn.net/zczy01234/article/details/85792410
 *   需要在Safari工具栏的“开发”中，勾选“允许远程自动化”；
 *
 *  js抓取工具  webster
 *  https://github.com/zhuyingda/webster?spm=ata.13261165.0.0.34b3537frFRCKC
 * @author weibo.xie
 * @date : create in 2:33 下午 2021/1/15
 */
public class MyWebDriver {
    public static void main(String[] args) throws InterruptedException {
        //  System.setProperty("webdriver.firefox.bin","C:\\Program Files\\Mozilla Firefox\\firefox.exe");
        //加载驱动
        //   System.setProperty("webdriver.firefox.marionette","geckodriver.exe");
        // https://blog.csdn.net/weixin_42299427/article/details/111985791
        // 没权限  xattr -d com.apple.quarantine chromedriver
          System.setProperty("webdriver.chrome.driver", "/usr/local/Caskroom/chromedriver/92.0.4515.107/chromedriver");
        // System.setProperty("webdriver.ie.driver","IEDriverServer.exe")
//       System.setProperty("webdriver.safari.driver", "/Users/weibo/library/safari/extensions");
//       System.setProperty("webdriver.safari.noinstall", "true");
     //  System.setProperty("webdriver.chrome.driver","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
//System.setProperty("webdriver.chrome.driver","/Users/weibo/soft/chromedriver");
       // options.add_argument('--proxy-server=xxxx:xxxx')
  // https://segmentfault.com/q/1010000021842787/a-1020000021865805
        //创建无Chrome无头参数
        ChromeOptions options=new ChromeOptions();
     //  options.addArguments("--proxy-server=http://140.205.171.24:80");
        options.addArguments("trpr-client-name=alihealth-reserve","trpr-proxy-socket-timeout=20000");
        options.addArguments("--trpr-client-name=alihealth-reserve","trpr-proxy-socket-timeout=20000");

        options.setCapability("--trpr-client-name","alihealth-reserve");
        options.setCapability("trpr-client-name","alihealth-reserve");
//chromeOptions.addArguments("-headless");
        String proxyServer = "140.205.171.24:80";
//       proxy
       Proxy proxy = new Proxy().setProxyType(Proxy.ProxyType.MANUAL).setHttpProxy(proxyServer).setSslProxy(proxyServer);
       options.setProxy(proxy);


        options.setCapability("proxy", proxy);
        WebDriver driver = new ChromeDriver(options);

        driver.get("http://zgcx.nhc.gov.cn:9090/unit/index");

        String title = driver.getTitle();
        WebElement body = driver.findElement(By.tagName("body"));

        System.err.println("title="+title);
        System.err.println("-------------------");
        System.err.println(driver.getPageSource());
     driver.quit();

    }


}